<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/fontello.css">
    <link rel="stylesheet" href="css/appvoralCSS.css">

    <link rel="stylesheet" href="css/ui-dialog.css">
    <script type="text/javascript" src="js/selector.js"></script>
    <script type="text/javascript" src="js/dialog-min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/sea.js"></script>
    <style>
         ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }

         ::-webkit-scrollbar-thumb {
            border-radius: 10px;
            background: #b1d8ff;
        }

         ::-webkit-scrollbar-track {
            border-radius: 10px;
            background: #e6e6e6;
        }

        #loadingImg {
            position: absolute;
            z-index: 2000;
            background-color: rgba(255, 255, 255, .9);
            margin: 0;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            -webkit-transition: opacity .3s;
            transition: opacity .3s;
        }

        #loadingImg img {
            width: 32px;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto
        }
    </style>
</head>

<body>
    <div id="myDiv"></div>
    <div style="display:none" id="loadingImg">
        <img src="img/loading1.gif" alt="">
    </div>
    <!--<div>1236</div>-->
</body>
<script type="text/javascript">
    // var ctxPath = '../../laboratory'

    $(function () {
        //默认显示工作流面板

        var id = null;
        var procInstType = null;
        // var from = null;
        var path = basePath();
        var url = path + "laboratory/workflow/workflowsubmitpre.htm";
        // if (getUrlField('from') != null && getUrlField('from') != undefined) {
        //     from = JSON.parse(getUrlField('from'))
        // }
        var data = {
            "procInstId": getUrlField('id'),
            "procInstType": getUrlField('procInstType'),
            "fromModel": getUrlField('fromModel'),
            "timestamp": new Date().getTime(),
        }
        console.log(data)
        $.ajax({
            type: "POST",
            headers: {
                "Content-Type": "application/json; charset=utf-8",
                'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
            },
            cache: false,
            url: url,
            dataType: "json",
            data: JSON.stringify(data),
            success: function (reponse) {
                if (reponse.code == 0) {

                    window.parent.postMessage({

                        cmd: 'loadingHide',
                        params: {
                            success: true,
                        }
                    }, '*');
                    var data1 = reponse.data;
                    $("#myDiv").append(data1);
                    $("#myDiv .approval-list").show();

                    //工作流显示隐藏点击
                    $("._showbutton").click(function () {
                        $("#myDiv .approval-list").toggle();
                    })
                    $("#myDiv ._showbutton").toggleClass('_hide').removeClass("icon-plus-circle").addClass("icon-minus-circle");
                    // 选择驳回时  默认选中第一个节点
                    var numbers = $("#reback").find("option");
                    for (var j = 1; j < numbers.length; j++) {
                        if ($(numbers[j]).val() == 'Process-task0') {
                            $(numbers[j]).attr("selected", "selected");
                        }
                    }

                    // $("#reback").value = "Process-task0"
                    // 如果是审核信息 隐藏掉操作栏和处理意见行
                    if (data.fromModel == 'look') {
                        $("#myDiv .row.approval-table").next(".row").hide();
                        $("#myDiv .row.processing-suggestions").hide();
                        $("#myDiv .row.approval-table").show();
                        $("#myDiv .approval-history .icon-check-empty").addClass('icon-check');
                    }

                }else{
                    window.parent.postMessage({
                        cmd: 'errorMsg',
                        params: {
                            success: true,
                        }
                    }, '*');
                }

            },
            error: function (e) {
                window.parent.postMessage({
                    cmd: 'errorMsg',
                    params: {
                        success: true,
                    }
                }, '*');
            }

        });



    });

</script>

<script>
    var closeDailog = false;

    function approve(data) {
        data = JSON.stringify(data);
        data = data.replaceAll("__", "");
        data = JSON.parse(data);
        data.id = getUrlField('id');
        data.procInstId = getUrlField('id');
        data.procInstType = getUrlField('procInstType');

        $("#loadingImg").show(); //点击提交按钮后加载中图片出现
        // return;
        var path = basePath();

        var url = path + "laboratory/workflow/workflowsubmit.htm";
        console.log(data);
        // return;
        $.ajax({
            type: "POST",
            headers: {
                "Content-Type": "application/json; charset=utf-8",
                'token':sessionStorage.getItem('loginAccount')?sessionStorage.getItem('loginAccount'):undefined
            },
            url: url,
            dataType: "json",
            data: JSON.stringify(data),
            success: function (reponse) {
                var data1 = reponse.data;
                $("#loadingImg").hide(); //成功后 加载隐藏
                var msg = "close"
                if(data.procInstType == 't_report_prepare'){
                  msg = 'reportReview'
                }
                window.parent.postMessage({
                    cmd: msg,
                    params: {
                        success: true,
                    }
                }, '*');

            },
            error: function (e) {
                $("#loadingImg").hide(); //成功后 加载隐藏
            }
        });
    }

    function basePath() {
        //获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
        var curWwwPath = window.document.location.href;
        //获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        //获取主机地址，如： http://localhost:8080
        var localhostPath = curWwwPath.substring(0, pos);
        //获取带"/"的项目名，如：/ems
        // var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
        //获取项目的basePath   http://localhost:8080/ems/
        // var basePath = localhostPath + projectName + "/";
        var basePath = localhostPath + "/";
        return basePath;
    };

    String.prototype.replaceAll = function (reallyDo, replaceWith, ignoreCase) {
        if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
            return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
        } else {
            return this.replace(reallyDo, replaceWith);
        }
    }

    function getUrlField(field) {
        return getFieldByUrl(window.location.search, field);
    }
    //获取url地址后面的参数
    function getFieldByUrl(url, field) {
        var reg = new RegExp("(^|&|\\?)" + field + "=([^&]*)(&|$)", "i");
        var r = url.substr(1).match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return "";
    };
    id = getUrlField('id');
    procInstType = getUrlField('procInstType');

</script>

</html>
